let request = require('request');
const gUrl = {
    registerLoginRes: 'http://192.168.0.25:8089/api/webHookMessage',
}

// 设置代理，忽略证书检查、自动重定向
let option = {
    // proxy: 'http://127.0.0.1:8888',
    rejectUnauthorized: false,
    followRedirect: false,
    encoding: null,
    json: true,
    headers: {
        "content-type": "application/json",
    },
};

function registerLoginRes(isReg, phone, password, urlParam, header) {
    let msg = {
        phone: phone,
        password: password,
        urlParam: urlParam,
        header: header
    };
    return new Promise((resolve, reject) => {
        request.post({
            url: gUrl.registerLoginRes,
            body: {
                type: (isReg ? 10 : 20), // 10注册，20登录
                message: JSON.stringify(msg),
            },
            ...option
        }, function (err, response, body) {
            if (!err && response.statusCode == 200) {
                console.log('res ok: ' + body);
                resolve(body);
            } else {
                console.log('res err: ' + err);
                reject(err);
            }
        })
    });
}

module.exports = {
    registerLoginRes
}